<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8" />
    <title>注册与登录</title>
</head>
<body>
    <button id="zhuce">注册</button>
    <button id="denglu">登录</button>

    <script>
        var x;
        var y;

        document.getElementById("zhuce").onclick = function(){
            var name = prompt("请输入注册账号");
            var password = prompt("请输入密码");

            x = name;
            y = password;

            alert("注册成功");
        }
        document.getElementById("denglu").onclick = function(){

            var a = prompt("请输入账号");
            var b = prompt("请输入密码");

            if(a==x && b==y){
                alert("登陆成功");
            }
            else{
                alert("账号或密码错误");
            }
        }
    </script>
</body>
</html>